package leecode

import "strconv"

func compress(chars []byte) int {
	low := 0
	last := 0
	size := len(chars)
	for last < size {
		temp := chars[last] //当前字符
		count := 0
		for last < size && temp == chars[last] {
			count++
			last++
		}
		//将当前字符写入慢指针的位置
		chars[low] = temp
		low++
		if count > 1 {
			arr := strconv.Itoa(count)
			for _, value := range arr {
				chars[low] = byte(value)
				low++
			}
		}
	}
	return low
}
